﻿<script src="../WFRes/_Scripts/bizqueryNew.js" type="text/javascript"></script>
<script type="text/javascript">

    var CustomColumns = [];
    // 若要添加自定义的列,请参考以下示例
    // CustomColumns.push({
    //    display: "自定义列标题1",//列标题
    //    width: "360px",//宽度
    //    //显示逻辑
    //    render: function (rowData, rowIndex) {
    //        return "<div>行号:" + rowIndex + "; 字段[ObjectID]值为:" + rowData.ObjectID + "</div>";
    //    }
    // });
    var SchemaCode = getUrlParam("SchemaCode") || "";//数据模型编码
    var QueryCode = getUrlParam("QueryCode") || "";//查询列表编码
    var outputPropertyMappings = getUrlParam("OutputParams") || "";
    var inputMappings = getUrlParam("InputParam");
    var CtrlID = getUrlParam("CtrlID") || "";
    var OpenType = getUrlParam("OpenType") || "";
    var IsPopup = getUrlParam("IsPopup") || "";

    var isFrame = OpenType == "1";
    var p = isFrame ? window.parent : window.opener;
    var isReturn = "True" == "True";
    var sourceObj = p == null ? null : (p.$ == null ? null : p.$.find("#" + CtrlID));
    var ActionVisible = "false";
    var Param_BizObjectID = "BizObjectID";
    var Param_SchemaCode = "SchemaCode";
    var LoginUrl = _PORTALROOT_GLOBAL + '/index.html#/platform/login';
    var EditBizObjectUrl = $.Controller.RunBizQuery.EditBizObject;
    var BizObjectHandlerUrl = $.Controller.RunBizQuery.InvokeMethod;
    var GridParam = { schemaCode: SchemaCode, queryCode: QueryCode };//表格数据请求参数
    var Controller = $.Controller.RunBizQuery.GetGridData;//表格数据请求地址
    var FilterData = [];//查询条件数组
    var DisplayFormats = [];//显示格式
    var GirdColumns = [];//表格显示列
    $(function () {
        initPage();
        BuildFilter(isFrame);
        BuildPage();
        GridParam = GetGridParam();
        LoadData();
        $("#H3ToolBar").AspLinkToolBar();
        $("#tableSearch").find("input").css("width", "110px");
    });

    //初始化页面数据
    function initPage() {
        if (SchemaCode && QueryCode) {
            $.ajax({
                url: $.Controller.RunBizQuery.GetRunBizQueryData,
                type: 'get',
                dataType: "json",
                data: { schemaCode: SchemaCode, queryCode: QueryCode },
                async: false,//同步执行
                success: function (result) {
                    if (result.Success) {
                        //
                        GirdColumns = result.Extend.GirdColumns;
                        DisplayFormats = result.Extend.DisplayFormats;
                        FilterData = result.Extend.FilterData;
                    } else {
                        parent.$.H3Dialog.Warn({ content: $.Lang(result.Message) });
                    }
                }
            });
        }
    };
    function btnSearchClick() {
        GridParam = GetGridParam();
        DocumentReady();
        LoadData();
        //if (masterDataGridManager) {
        //    $("#hfPageSize").val(masterDataGridManager.options.pageSize);
        //}
        $("#tableSearch").find("input").css("width", "110px");
    }

    function btnConfirmClick() {
    	
    	//
        if (!isReturn) return;
        var maps = outputPropertyMappings.split("|");
        var resultItem = {};
        for (var i = 0; i < maps.length; i++) {
            if (maps[i].length == 0) continue;
            var itemName = maps[i].split(',')[0];
            var propertyName = maps[i].split(',')[1];
            var propertyArray = propertyName.split(';');//关联表单需要一个控件绑定两个值
            ///var dataArry = [];
        	var resultVal = "";
            for(var jIndex = 0; jIndex < checkedCustomer.length;jIndex++){
            	var data = checkedCustomer[jIndex];
            	
            	if (data[propertyName] && data[propertyName].toString().indexOf("EditUser.aspx?Mode=View&ID=") > -1) {
                    // 仅支持参与者单人情况
                    resultItem[itemName] = data[propertyName].split("EditUser.aspx?Mode=View&ID=")[1].split("'")[0];
                } else {
                    if (propertyArray.length > 0) {
                        
                        for(var j=0;j<propertyArray.length;j++){
                        	resultVal += data[propertyArray[j]] +";";
                        }
                        
                    } else {
                    	resultVal += data[propertyName]+";";
                    }
                }
            	
            	
            }
            
            if(dataArry.length > 0){
                resultItem[itemName] = dataArry;
        	}else{
        		resultItem[itemName] = resultVal.substring(0,resultVal.length-1);
        	}
            
            /*if (data[propertyName] && data[propertyName].toString().indexOf("EditUser.aspx?Mode=View&ID=") > -1) {
                // 仅支持参与者单人情况
                resultItem[itemName] = data[propertyName].split("EditUser.aspx?Mode=View&ID=")[1].split("'")[0];
            } else {
                if (propertyArray.length > 0) {
                    var dataArry = [];
                    for(var j=0;j<propertyArray.length;j++){
                        dataArry[j] = data[propertyArray[j]];
                    }
                    resultItem[itemName] = dataArry;
                } else {
                    resultItem[itemName] = data[propertyName];
                }
            }*/
        }
        //新开窗查询模式
        if (sourceObj && p[sourceObj[0].id].ListMasterCallBack) {
            p[sourceObj[0].id].ListMasterCallBack(resultItem);
            if (p.ListMasterCallBack) p.ListMasterCallBack(sourceObj);
        }
        else {
            //兼容旧开窗查询模式
            $.each(resultItem, setParentControlValue);
            if (p.ListMasterCallBack) p.ListMasterCallBack(sourceObj);
            isFrame ? window.parent.$('#' + CtrlID + '_MasterData').hide() : window.close();
        }
        //这里回掉页面的传值方法
        /*if (sourceObj && p[sourceObj[0].id].ListMasterCallBack) {
            p[sourceObj[0].id].ListMasterCallBack(checkedCustomer);
            if (p.ListMasterCallBack) p.ListMasterCallBack(sourceObj);
        }*/
    }
</script>
<style>
    .tableList input[type="text"], .tableList input[type="password"], .tableList select, .tableList input[type="file"] {
        width: auto !important;
    }
</style>
<body>
    <form id="form1">
        <div>
            <div id="H3ToolBar">
                <a onclick="btnSearchClick();" id="btnSearch" data-icon="l-icon fa fa-search" title="query" href="javascript:void(0)" data-lang="GlobalButton.Search">查询</a>
                <a onclick="btnConfirmClick();" id="btnConfirm" data-icon="l-icon fa" href="javascript:void(0)" data-lang="GlobalButton.Confirm">确认</a>
            </div>
            <div id="panelSearch">
                <div class="H3Panel">
                    <table id="tableSearch" border="0"></table>
                </div>
            </div>
            <div class="H3Panel">
                <div id="excludePanel">
                    <div id="masterDataGrid"></div>
                    <input type="hidden" name="hfPageSize" id="hfPageSize" value="20" />
                </div>
            </div>
        </div>
    </form>
</body>

